package com.example.administrator.yuejian_15.activity;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.yuejian_15.R;
import com.example.administrator.yuejian_15.bean.SuccessBean;
import com.example.administrator.yuejian_15.listener.TListener;
import com.example.administrator.yuejian_15.model.PxAddOrderModel;
import com.squareup.picasso.Picasso;

public class PxBmActivity extends BaseActivity implements View.OnClickListener{

    TextView pxbm1,pxbm2,pxbm3,pxbm4,pxbm5,pxbm6,pxbm7;
    ImageView pxbm_img,pxbm_fh;
    EditText pxbm_username,pxbm_num;
    Button pxbm_bm;

    String pxid,pxname,pxpic,pxintro,pxclassintro,pxtime,pxaddress,pxpeoplenum;
    int pxprice;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_px_bm);
        pxbm1=(TextView)findViewById(R.id.pxbm1);
        pxbm2=(TextView)findViewById(R.id.pxbm2);
        pxbm3=(TextView)findViewById(R.id.pxbm3);
        pxbm4=(TextView)findViewById(R.id.pxbm4);
        pxbm5=(TextView)findViewById(R.id.pxbm5);
        pxbm6=(TextView)findViewById(R.id.pxbm6);
        pxbm7=(TextView)findViewById(R.id.pxbm7);

        pxbm_img=(ImageView)findViewById(R.id.pxbm_img);
        pxbm_fh=(ImageView)findViewById(R.id.pxbm_fh);

        pxbm_username=(EditText)findViewById(R.id.pxbm_username);
        pxbm_num=(EditText)findViewById(R.id.pxbm_num);

        pxbm_bm=(Button)findViewById(R.id.pxbm_bm);

        pxid=getIntent().getStringExtra("pxid");
        pxname=getIntent().getStringExtra("pxname");
        pxpic=getIntent().getStringExtra("pxpic");
        pxintro=getIntent().getStringExtra("pxintro");
        pxclassintro=getIntent().getStringExtra("pxclassintro");
        pxtime=getIntent().getStringExtra("pxtime");
        pxaddress=getIntent().getStringExtra("pxaddress");
        pxprice=getIntent().getIntExtra("pxprice",pxprice);
        pxpeoplenum=getIntent().getStringExtra("pxpeoplenum");

        pxbm1.setText("培训名称:"+pxname);
        pxbm2.setText("培训简介:"+pxintro);
        pxbm3.setText("培训须知:"+pxclassintro);
        pxbm4.setText("培训时间:"+pxtime);
        pxbm5.setText("培训地址:"+pxaddress);
        pxbm6.setText("培训价格:"+pxprice);
        pxbm7.setText("培训报名人数:"+pxpeoplenum);
        Picasso.with(PxBmActivity.this).load(pxpic).into(pxbm_img);


    }

    @Override
    void initEvent() {
        pxbm_fh.setOnClickListener(this);
        pxbm_bm.setOnClickListener(this);

    }

    @Override
    void initDate() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.pxbm_fh:
                finish();
                break;
            case R.id.pxbm_bm:
                String username = pxbm_username.getText().toString().trim();
                String num = pxbm_num.getText().toString().trim();
                String uid = getid();
                if (username.equals("")||num.equals("")){
                    Toast.makeText(PxBmActivity.this,"填写信息不能为空",Toast.LENGTH_SHORT).show();
                }
                else {
                    PxAddOrderModel pxAddOrderModel=new PxAddOrderModel();
                    pxAddOrderModel.addPxOrder(uid,username,pxid,num,successBeanTListener);
             //      Toast.makeText(PxBmActivity.this,username+num+"---"+uid+"--"+pxid,Toast.LENGTH_SHORT).show();
                }
                break;

        }
    }
    TListener<SuccessBean> successBeanTListener=new TListener<SuccessBean>() {
        @Override
        public void onResponse(SuccessBean successBean) {
            String success = successBean.getSuccess();
            if (success.equals("1")){
                Toast.makeText(PxBmActivity.this,"报名成功",Toast.LENGTH_SHORT).show();
                finish();

            }
            else{
                Toast.makeText(PxBmActivity.this,"报名失败",Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(PxBmActivity.this,"报名失败，或网络失败",Toast.LENGTH_SHORT).show();
        }
    };

}
